<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/11/2
 * Time: 14:44
 */

namespace app\api\model;


class CardImg extends BaseModel
{
    protected $autoWriteTimestamp = true;
    protected $updateTime = false;
    protected $hidden=['w_id','name','key','from','order','create_time','delete_time'];

    public function getUrlAttr($value,$data){
        return $this->prefixImg($value,$data);
    }

    /**
     * 创建图片
     * @param $info
     * @return $this
     */
    public static function createImg($info)
    {
        $data['name']=$info->fname;
        $data[ 'url']=$info->fkey;
        $data['key']=$info->fkey;
        $data['type'] = $info->type;
        $data['from'] = 2;
        $data['w_id'] = $info->uid;
        return self::create($data);
    }

    /**
     * 获取图片
     * @param $img_id
     * @return null|static
     */
    public static function getImg($img_id){
        return self::get($img_id);
    }
    /**
     * 删除图片
     * @param $img_id
     * @return int
     */
    public static function deleteImg($img_id){
        return self::destroy($img_id);
    }

    /**
     * 根据用户id获取图片
     * @param $wu_id
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getImgByUid($wu_id){
        return self::where('w_id','=',$wu_id)
            ->where('type','=','introduce')
            ->select();
    }
}